name: Tests

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  ingester:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version: '1.21.1'
    
    - name: Build
      working-directory: ./src/ingester
      run: go build -v ./...
    
    - name: Code Format Check (gofmt)
      working-directory: ./src/ingester
      run: |
        if [ -n "$(gofmt -l .)" ]; then
          echo "Go code is not formatted:"
          gofmt -d .
          exit 1
        fi
    
    - name: Test
      working-directory: ./src/ingester
      run: go test -v ./...
